class ArticlesController < ApplicationController
  # GET /articles
  # GET /articles.xml
   uses_tiny_mce :options => {
    :width => '620',
    :height => '400',
    :theme =>  "advanced",
    :plugins => "paste,preview,insertdatetime,media",
    :theme_advanced_buttons1 => "formatselect,fontselect,fontsizeselect,|,forecolor,backcolor,|,mymenubutton,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,bullist,numlist",
    :theme_advanced_buttons2 =>",outdent,indent,|,undo,redo,|,cut,copy,paste,pastetext,pasteword,|,anchor,image,media,link,unlink,blockquote,|,cleanup,insertdate,inserttime,preview,code,|,help,",
    :theme_advanced_buttons3 => "",
    :theme_advanced_toolbar_location => "top",
    :theme_advanced_toolbar_align => "left",
    :theme_advanced_resizing => true,
    :theme_advanced_resize_horizontal => false,
  },
    :only => [:new,:edit]

  layout 'admin'
  
  def index
    @articles = Article.all

    respond_to do |format|
      format.html 
      format.xml  { render :xml => @articles }
    end
  end
  

  # GET /articles/1
  # GET /articles/1.xml
  def show
    @article = Article.find(params[:id])

    respond_to do |format|
      format.html {render :layout => 'display'}
      format.xml  { render :xml => @article }
    end
  end

  # GET /articles/new
  # GET /articles/new.xml
  def new
    @article = Article.new

    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @article }
    end
  end

  # GET /articles/1/edit
  def edit
    @article = Article.find(params[:id])
  end

  # POST /articles
  # POST /articles.xml
  def create
    @article = Article.new(params[:article])

    respond_to do |format|
      if @article.save
        flash[:notice] = 'Article was successfully created.'
        format.html { redirect_to(news_path(@article)) }
        format.xml  { render :xml => @article, :status => :created, :location => @article }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @article.errors, :status => :unprocessable_entity }
      end
    end
  end

  # PUT /articles/1
  # PUT /articles/1.xml
  def update
    @article = Article.find(params[:id])

    respond_to do |format|
      if @article.update_attributes(params[:article])
        flash[:notice] = 'Article was successfully updated.'
        format.html { redirect_to(news_path(@article)) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @article.errors, :status => :unprocessable_entity }
      end
    end
  end

  # DELETE /articles/1
  # DELETE /articles/1.xml
  def destroy
    @article = Article.find(params[:id])
    @article.destroy

    respond_to do |format|
      format.html { redirect_to(articles_url) }
      format.xml  { head :ok }
    end
  end
end
